<?php
// created by: alfin akhret
// related files :
// model/mdue_date.php
// view/f-due-date.php
// view/grid-due-date.php
// library/serversidedatatables.php
class Mdue_date extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('serversidedatatables');
	}

	//cari data jatuh tempo
	function get_due_date($cluster_id = '')
	{
		$user_id = "";
		if($this->session->userdata('user_id') != "")
		{
			$user_id = $this->session->userdata('user_id');
		}
		else {
			$user_id = $this->session->userdata('username');
		}

		//operasi pengambilan data jatuh tempo sell in

		    $sIndexColumn = "no_sell_in"; 
        $status="";
        $defaultOrder = "0";
        $orderingSequence = "desc";

        $aColumns = array("no_sell_in", "user_name", "to_char", "top_day", "tgl_jatuh_tempo", "jatuh_tempo");

        $str1 = array(" , ", ", ' '");
        $str2 = array(" ", " ");
        $inputQuery = "select ".str_replace($str1, $str2, implode(", ", $aColumns))." from v_ssp_due_date_sell_in 
        				where cluster_id = $cluster_id and istatus in(1, 2) and top_id != '1' and cast(tgl_jatuh_tempo as date) >= current_date";

        return $this->serversidedatatables->executeServerSideProcess($defaultOrder, $status, $user_id, $inputQuery, $aColumns, $sIndexColumn, $orderingSequence);
           
		
	}

	//close kasus jatuh tempo
	function close($sell_in_id)
	{
		$this->db->where('sell_in_id', $sell_in_id);
		$this->db->update('t_trx_sell_in', array("istatus" => '3')); 
	}

}